﻿using System;
using System.Globalization;

namespace JTLeigh.Commerce.Spencer.Core.Common
{

	/// <summary>
	/// <see langword="static" /> methods for working with cultures.
	/// </summary>
	public static class CultureTools
    {

        #region Methods

        /// <summary>
        /// Gets the name of the specified culture.
        /// </summary>
        /// <param name="cultureId">The <see cref="Int32"/> LCID of the culture.</param>
        /// <returns>The name of the culture in the format &lt;languageCode&gt;-&lt;countryCode&gt;.</returns>
        public static string GetCultureName(int cultureId)
        {
            return CultureInfo.GetCultureInfo(cultureId).Name;
        }

		/// <summary>
		/// Compares two cultures and determines if they share a common language.
		/// </summary>
		/// <param name="culture1Id">The <see cref="Int32"/> LCID of the first culture.</param>
		/// <param name="culture2Id">The <see cref="Int32"/> LCID of the second culture.</param>
		/// <returns><see langword="true"/> if the two cultures share a common language, 
		/// <see langword="false"/> otherwise.</returns>
		public static bool CompareCultureLanguages(int culture1Id, int culture2Id)
		{
			CultureInfo culture1;
			CultureInfo culture2;
			bool result;

			culture1 = new CultureInfo(culture1Id);
			culture2 = new CultureInfo(culture2Id);
			result = culture1.ThreeLetterISOLanguageName.Equals(culture2.ThreeLetterISOLanguageName, StringComparison.OrdinalIgnoreCase);
			return result;
        }

        #endregion // Methods

    }

}
